//
//  main.m
//  openmove
//
//  Created by Sam le Pirate on 10/11/05.
//  Copyright openmove 2005. All rights reserved.
//
#include "openmove_Prefix.h"
#include "OgreEngine.h"
#include "SceneBase.h"
#include "SceneEcriture.h"
#include "SceneCubenu.h"
#include "SceneLoupVoyeur.h"
#include "ScenePoursuite.h"
#include "SceneWater.h"
#include "ScenePluie.h"
#include "SceneRencontre.h"
#include "SceneInBed.h"
#include "SceneInBedHaut.h"
#include "ScenePetitPot.h"
#include "SceneGlamPetitLoup.h"
#include "SceneSouffle.h"
#include "SceneBlanche.h"
#include "SceneFugana.h"
#include "SceneTestParticule.h"
#include "SceneTestRenaissance.h"
#include "SceneTestFur.h"
#include "NetServer.h"
#include "NetClient.h"
#include "SyncLib/SyncManager.h"

#include "SimpleFrameListener.h"
#include "KeyListener.h"
#include "ExampleFrameListener.h"
#include "SkeletalAnimationFrameListener.h"

#include <sys/types.h>

#include <xercesc/util/PlatformUtils.hpp>
XERCES_CPP_NAMESPACE_USE

#define SCENE_INTRO 0
#define SCENE_LOUPVOYEUR 0
#define SCENE_POURSUITE 0
#define SCENE_RENCONTRE 0
#define SCENE_PETITPOT 0
#define SCENE_FARFALLE 0
#define SCENE_INBED 0
#define SCENE_INBEDSOL 0
#define SCENE_GLAM 0
#define SCENE_ECRITURE 0
#define SCENE_FUGANA 0
#define SCENE_PEAUDULOUP 0
#define SCENE_SOUFFLE 0
#define SCENE_BLANCHE 0

#ifdef __cplusplus
extern "C"
{
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
	DWORD mask = 15;
	SetThreadAffinityMask(GetCurrentThread(), mask);
	XMLPlatformUtils::Initialize();

	String CmdLine = strCmdLine;
	String ServerAddress;
	ENetConfig NetConfig;

	String::size_type posR = CmdLine.find("clientR");
	String::size_type posL = CmdLine.find("clientL");
	
	if (String::npos != posR)
	{
		ServerAddress = CmdLine.substr(posR + 8);
		NetConfig = e_NCClientR;
	}
	else
	if (String::npos != posL)
	{
		ServerAddress = CmdLine.substr(posL + 8);
		NetConfig = e_NCClientL;
	}
	else
	if (String::npos != CmdLine.find("server"))
	{
		NetConfig = e_NCServer;
	}
	else
	{
		NetConfig = e_NCNone;
	}

	COgreEngine Engine;
	Engine.Create();

srand(0);

	//Engine.AddDefaultLight();

	CSyncManager::getSingleton().m_IsServer = NetConfig == e_NCServer || NetConfig == e_NCNone;

	std::vector<CSceneBase *> Scenes;

	Utils::initializeFromXml("test.xml", Scenes, &Engine, NetConfig);

#if SCENE_INTRO
	//Scene Intro
	CSceneTestRenaissance TestRenaissance(Engine, "Intro", 0);
	Scenes.push_back(&TestRenaissance);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("TestRenaissanceglam-petitsloups", "glam-petitsloups.mesh", true));
		Nodes.push_back(SNode("TestRenaissanceglam-petitsloups", "TestRenaissanceglam-petitsloups"));

		Lights.push_back(SLight("TestRenaissanceAmbient", Vector3::ZERO, ColourValue(0.1f, 0.1f, 0.1f, 1.0f)));
		Lights.push_back(SLight("TestRenaissancedirectionalLight1", Vector3::ZERO, ColourValue(0.7f, 0.7f, 0.7f, 1.0f), ColourValue::White, Light::LT_DIRECTIONAL, Vector3(0, -0.5, 1)));

		TestRenaissance.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif
#if SCENE_LOUPVOYEUR
	//Scene Loup Voyeur
	CSceneLoupVoyeur LoupVoyeur(Engine, "LoupVoyeur", 1);
	Scenes.push_back(&LoupVoyeur);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("loup-voyeur-env", "loup-voyeur-env.mesh"));
		Nodes.push_back(SNode("loup-voyeur-env", "loup-voyeur-env"));

		Entities.push_back(SEntity("loup-voyeur_ana", "loup-voyeur_ana.mesh"));
		Nodes.push_back(SNode("loup-voyeur_ana", "loup-voyeur_ana"));

		Entities.push_back(SEntity("loup-voyeur_nco", "loup-voyeur_nco.mesh"));
		Nodes.push_back(SNode("loup-voyeur_nco", "loup-voyeur_nco"));

		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.0f, 0.0f, 0.0f, 1.0f)));
		Vector3 direction = Quaternion(Degree(-21.6), Vector3::UNIT_X) * Quaternion(Degree(-6.8), Vector3::UNIT_Y) * Quaternion(Degree(0), Vector3::UNIT_Z) *
			-Vector3::UNIT_Z;
		Lights.push_back(SLight("loup-voyeur-pointLight2", Vector3(221.814, 190.76, 963.616), ColourValue(0.5f, 0.5f, 0.5f, 1.0f), ColourValue::Black, Light::LT_DIRECTIONAL, direction, false));

		LoupVoyeur.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif
#if SCENE_POURSUITE
	//Scene Poursuite
	CScenePoursuite Poursuite(Engine, "Poursuite", 2);
	Scenes.push_back(&Poursuite);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("poursuite-foret-herbe1", "poursuite-foret-herbe1.mesh"));
		Entities.push_back(SEntity("poursuite-foret-herbe2", "poursuite-foret-herbe2.mesh"));
		Nodes.push_back(SNode("poursuite-foret-herbe1", "poursuite-foret-herbe1"));
		Nodes.push_back(SNode("poursuite-foret-herbe2", "poursuite-foret-herbe2"));

		Entities.push_back(SEntity("poursuite-foret-ana", "poursuite-foret-ana.mesh"));
		Nodes.push_back(SNode("poursuite-foret-ana", "poursuite-foret-ana"));

		Entities.push_back(SEntity("poursuite-foret-sol", "poursuite-foret-sol.mesh"));
		Nodes.push_back(SNode("poursuite-foret-sol", "poursuite-foret-sol"));
		
		//Entities.push_back(SEntity("poursuite-foret-camera", "poursuite-foret-camera.mesh"));
		//Entities.push_back(SEntity("poursuite-foret-camera-zoom", "poursuite-foret-camera-zoom.mesh"));
		Entities.push_back(SEntity("poursuite-foret-light", "poursuite-foret-light.mesh"));
		
		Entities.push_back(SEntity("poursuite-foret-lumiere1", "poursuite-foret-lumiere1.mesh"));
		Nodes.push_back(SNode("poursuite-foret-lumiere1", "poursuite-foret-lumiere1"));
		Entities.push_back(SEntity("cam-tremblement", "cam-tremblement.mesh"));
		Nodes.push_back(SNode("cam-tremblement", "cam-tremblement"));
		//Entities.push_back(SEntity("cam-trav", "cam-trav.mesh"));
		//Nodes.push_back(SNode("cam-trav", "cam-trav"));


		//Nodes.push_back(SNode("poursuite-foret-camera", "poursuite-foret-camera"));
		//Nodes.push_back(SNode("poursuite-foret-camera-zoom", "poursuite-foret-camera-zoom"));
		Nodes.push_back(SNode("poursuite-foret-light", "poursuite-foret-light"));
		
		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.0f, 0.0f, 0.0f, 0.0f)));
		Lights.push_back(SLight("poursuite-pointLight2", Vector3(-369.5f, 268.7f, 59.0f), ColourValue(0.9f, 0.9f, 0.9f), ColourValue(0.8f, 0.8f, 0.8f), Light::LT_DIRECTIONAL, Vector3(0, -0.1, 1)));

		Poursuite.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif
#if SCENE_RENCONTRE
	//Scene Rencontre
	CSceneRencontre Rencontre(Engine, "Rencontre", 3);
	Scenes.push_back(&Rencontre);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		for (int i = 1; i < 22; ++i)
		{
			String Name = "rencontre-tronc" + StringConverter::toString(i);
			Entities.push_back(SEntity(Name, Name + ".mesh"));
			Nodes.push_back(SNode(Name, Name));
		}
		for (int i = 1; i < 22; ++i)
		{
			String Name = "rencontre-feuille" + StringConverter::toString(i);
			Entities.push_back(SEntity(Name, Name + ".mesh"));
			Nodes.push_back(SNode(Name, Name));
		}
		Entities.push_back(SEntity("sol-rencontre", "sol-rencontre.mesh"));
		Nodes.push_back(SNode("sol-rencontre", "sol-rencontre"));

		Entities.push_back(SEntity("rencontre-clones-ana", "rencontre-clones-ana.mesh", true));
		Nodes.push_back(SNode("rencontre-clones-ana", "rencontre-clones-ana"));
		Entities.push_back(SEntity("rencontre-clones-nco", "rencontre-clones-nco.mesh", true));
		Nodes.push_back(SNode("rencontre-clones-nco", "rencontre-clones-nco"));

		Entities.push_back(SEntity("joint-cam-rencontre", "joint-cam-rencontre.mesh"));
		Nodes.push_back(SNode("joint-cam-rencontre", "joint-cam-rencontre"));
		
		
		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.0f, 0.0f, 0.0f, 1.0f)));

		Rencontre.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif
#if SCENE_PETITPOT
	//Scene PetitPot
	CScenePetitPot PetitPot(Engine, "PetitPot", 4);
	Scenes.push_back(&PetitPot);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		for (int i = 1; i < 22; ++i)
		{
			String Name = "PetitPot-tronc" + StringConverter::toString(i);
			String FileName = "rencontre-tronc" + StringConverter::toString(i) + ".mesh";
			Entities.push_back(SEntity(Name, FileName));
			Nodes.push_back(SNode(Name, Name));
		}
		for (int i = 1; i < 22; ++i)
		{
			String Name = "PetitPot-feuille" + StringConverter::toString(i);
			String FileName = "rencontre-feuille" + StringConverter::toString(i) + ".mesh";
			Entities.push_back(SEntity(Name, FileName));
			Nodes.push_back(SNode(Name, Name));
		}
		Entities.push_back(SEntity("couple_petit_pot", "couple_petit_pot.mesh", true));
		Nodes.push_back(SNode("couple_petit_pot", "couple_petit_pot"));
		Entities.push_back(SEntity("petit_pot_sol", "petit_pot_sol.mesh"));
		Nodes.push_back(SNode("petit_pot_sol", "petit_pot_sol"));

		Entities.push_back(SEntity("petit_pot_camera", "petit_pot_camera.mesh"));
		Nodes.push_back(SNode("petit_pot_camera", "petit_pot_camera"));
		
		
		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.0f, 0.0f, 0.0f, 1.0f)));

		PetitPot.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif	
#if SCENE_FARFALLE
	//Scene Water
	CSceneWater Water(Engine, "Water", 5);
	Scenes.push_back(&Water);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("farfale", "farfale.mesh"));
		Nodes.push_back(SNode("farfale", "farfale"));
		
		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.0f, 0.0f, 0.0f, 1.0f)));
		Lights.push_back(SLight("farfale-pointLight", Vector3(0, 300, 50), ColourValue::White));

		//Entities.push_back(SEntity("inbed_haut-camera", "inbed_haut_cam.mesh"));
		//Nodes.push_back(SNode("inbed_haut-camera", "inbed_haut-camera"));
		
		Water.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif
	//Scene Pluie
	/*
	CScenePluie Pluie(Engine, "Pluie");
	Scenes.push_back(&Pluie);
	{
		CSceneBase::TCreatorEntities PluieEntities;
		CSceneBase::TCreatorNodes PluieNodes;
		CSceneBase::TCreatorLights PluieLights;

		PluieEntities.push_back(SEntity("ana-fuguana", "ana-fuguana.mesh"));
		PluieNodes.push_back(SNode("ana-fuguana", "ana-fuguana"));
		
		PluieLights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.75f, 0.75f, 0.75f, 1.0f)));
		PluieLights.push_back(SLight("Pluie-pointLight", Vector3(500, 200, 500), ColourValue::White));

		Pluie.Create(PluieEntities, PluieNodes, PluieLights, NetConfig);
	}
	*/

#if SCENE_INBED
	//Scene InBedHaut
	CSceneInBedHaut InBedHaut(Engine, "InBedHaut", 6);
	Scenes.push_back(&InBedHaut);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("inbed_haut_ana", "inbed_haut_ana.mesh", true));
		Nodes.push_back(SNode("inbed_haut_ana", "inbed_haut_ana"));
		Entities.push_back(SEntity("inbed_haut_nco", "inbed_haut_nco.mesh", true));
		Nodes.push_back(SNode("inbed_haut_nco", "inbed_haut_nco"));

		Entities.push_back(SEntity("decor-inbed_haut_camera", "decor-inbed_haut_camera.mesh"));
		Nodes.push_back(SNode("decor-inbed_haut_camera", "decor-inbed_haut_camera"));

		Entities.push_back(SEntity("decor-inbed_haut_sol", "decor-inbed_haut_sol.mesh"));
		Nodes.push_back(SNode("decor-inbed_haut_sol", "decor-inbed_haut_sol"));
		Entities.push_back(SEntity("decor-inbed_haut_nid", "decor-inbed_haut_nid.mesh"));
		Nodes.push_back(SNode("decor-inbed_haut_nid", "decor-inbed_haut_nid"));
		Entities.push_back(SEntity("decor-inbed_haut_plante", "decor-inbed_haut_plante.mesh"));
		Nodes.push_back(SNode("decor-inbed_haut_plante", "decor-inbed_haut_plante", Vector3(0, -50, 0)));

		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.0f, 0.0f, 0.0f, 1.0f)));

		Vector3 spot = (Quaternion(Degree(0), Vector3::UNIT_Z) *
			Quaternion(Degree(164.0), Vector3::UNIT_Y) *
			Quaternion(Degree(-42.0), Vector3::UNIT_X)) * -Vector3::UNIT_Z;
		Lights.push_back(SLight("InBedHaut-pointLight2", Vector3(-114.644, 292.124, -382.508), ColourValue(0.3490f, 0.3094f, 0.2542f, 1.0f), ColourValue::Black, Light::LT_SPOTLIGHT, spot));

		//Vector3 directional = Quaternion(Degree(-56.318), Vector3::UNIT_X) * -Vector3::UNIT_Z;
		//Lights.push_back(SLight("InBedHaut-directionalLight1", Vector3(0, 200, 0), ColourValue(1.0f, 1.0f, 1.0f, 1.0f), ColourValue::Black, Light::LT_DIRECTIONAL, directional, false));

		InBedHaut.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif

#if SCENE_INBEDSOL
	//Scene InBed
	CSceneInBed InBed(Engine, "InBed", 7);
	Scenes.push_back(&InBed);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("inbed-sol-sol", "inbed-sol-sol.mesh"));
		Nodes.push_back(SNode("inbed-sol-sol", "inbed-sol-sol"));
		//Entities.push_back(SEntity("inbed-wave", "inbed-wave.mesh"));
		//Nodes.push_back(SNode("inbed-wave", "inbed-wave"));
		Entities.push_back(SEntity("inbed-clone-nco", "inbed-clone-nco.mesh"));
		Nodes.push_back(SNode("inbed-clone-nco", "inbed-clone-nco"));
		Entities.push_back(SEntity("inbed-clone-ana", "inbed-clone-ana.mesh"));
		Nodes.push_back(SNode("inbed-clone-ana", "inbed-clone-ana"));
		Entities.push_back(SEntity("inbed-sol-video", "inbed-sol-video.mesh"));
		Nodes.push_back(SNode("inbed-sol-video", "inbed-sol-video"));
		
		
		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.0f, 0.0f, 0.0f, 1.0f)));
		Lights.push_back(SLight("InBed-pointLight1", Vector3(-356.216, 134.224, -10.407), ColourValue(1.0f, 1.0f, 1.0f, 1.0f), ColourValue::Black, Light::LT_DIRECTIONAL, Vector3(-0.3, 0, 1)));

		InBed.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif
#if SCENE_GLAM
	//Scene GlamPetitLoup
	CSceneGlamPetitLoup GlamPetitLoup(Engine, "GlamPetitLoup", 8);
	Scenes.push_back(&GlamPetitLoup);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("glam-petitsloups", "glam-petitsloups.mesh", true));
		Nodes.push_back(SNode("glam-petitsloups", "glam-petitsloups"));
		Entities.push_back(SEntity("glam-petitsloups-arbre", "glam-petitsloups-arbre.mesh", true));
		Nodes.push_back(SNode("glam-petitsloups-arbre", "glam-petitsloups-arbre"));
		Entities.push_back(SEntity("glam-petitsloups-sol", "glam-petitsloups-sol.mesh"));
		Nodes.push_back(SNode("glam-petitsloups-sol", "glam-petitsloups-sol"));
		
		//Entities.push_back(SEntity("glam-petitsloups-loup", "glam-petitloups-loup.mesh"));
		//Nodes.push_back(SNode("glam-petitsloups-loup", "glam-petitsloups-loup"));
		
		Entities.push_back(SEntity("glam-petitsloups-bones", "joint_loups.mesh"));
		Nodes.push_back(SNode("glam-petitsloups-bones", "glam-petitsloups-bones"));

		Entities.push_back(SEntity("glam_camera", "glam_camera.mesh"));
		Nodes.push_back(SNode("glam_camera", "glam_camera"));

		Vector3 to(4.523, 2.744, 1.456);
		Vector3 from(5.811, 3.814, 2.253);
		Vector3 dir = to - from;
		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.1f, 0.1f, 0.1f, 1.0f)));
		Lights.push_back(SLight("GlamPetitLoup-directionalLight1", Vector3::ZERO, ColourValue(0.7f, 0.7f, 0.7f, 1.0f), ColourValue::White, Light::LT_DIRECTIONAL, dir));

		GlamPetitLoup.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif
#if SCENE_ECRITURE
	//Scene Ecriture
	CSceneEcriture Ecriture(Engine, "Ecriture", 9);
	Scenes.push_back(&Ecriture);
	{
		CSceneBase::TCreatorEntities EcritureEntities;
		CSceneBase::TCreatorNodes EcritureNodes;
		CSceneBase::TCreatorLights EcritureLights;

		EcritureEntities.push_back(SEntity("ecriture_bones", "ecriture_bones.mesh"));
		EcritureNodes.push_back(SNode("ecriture_bones", "ecriture_bones"));
		
		EcritureLights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.2f, 0.2f, 0.2f, 1.0f)));

		Ecriture.Create(EcritureEntities, EcritureNodes, EcritureLights, NetConfig);
	}
#endif
#if SCENE_FUGANA
	//Scene Fugana
	CSceneFugana Fugana(Engine, "Fugana", 10);
	Scenes.push_back(&Fugana);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		for (int i = 1; i < 22; ++i)
		{
			String Name = "Fugana-tronc" + StringConverter::toString(i);
			String FileName = "rencontre-tronc" + StringConverter::toString(i) + ".mesh";
			Entities.push_back(SEntity(Name, FileName));
			Nodes.push_back(SNode(Name, Name));
		}
		for (int i = 1; i < 22; ++i)
		{
			String Name = "Fugana-feuille" + StringConverter::toString(i);
			String FileName = "rencontre-feuille" + StringConverter::toString(i) + ".mesh";
			Entities.push_back(SEntity(Name, FileName));
			Nodes.push_back(SNode(Name, Name));
		}
		Entities.push_back(SEntity("fugana-der-sol", "fugana-der-sol.mesh"));
		Nodes.push_back(SNode("fugana-der-sol", "fugana-der-sol"));
		Entities.push_back(SEntity("fugana-der-sol2", "fugana-der-sol2.mesh"));
		Nodes.push_back(SNode("fugana-der-sol2", "fugana-der-sol2"));
		Entities.push_back(SEntity("fugana-der-camera", "fugana-der-camera.mesh"));
		Nodes.push_back(SNode("fugana-der-camera", "fugana-der-camera"));
		Entities.push_back(SEntity("ana-prise1", "ana-prise1.mesh", true));
		Nodes.push_back(SNode("ana-prise1", "ana-prise1"));
		Entities.push_back(SEntity("ana-prise2", "ana-prise2.mesh", true));
		Nodes.push_back(SNode("ana-prise2", "ana-prise2"));
		Entities.push_back(SEntity("Ana-prise-quantic", "Ana-prise-quantic.mesh", true));
		Nodes.push_back(SNode("Ana-prise-quantic", "Ana-prise-quantic"));
		

		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.5f, 0.5f, 0.5f, 1.0f)));

		Fugana.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif

	//Scene Cube Nu
#if SCENE_PEAUDULOUP
	CSceneCubenu Cubenu(Engine, "Cubenu", 11);
	Scenes.push_back(&Cubenu);
	{
		CSceneBase::TCreatorEntities CubenuEntities;
		CSceneBase::TCreatorNodes CubenuNodes;
		CSceneBase::TCreatorLights CubenuLights;

		CubenuEntities.push_back(SEntity("cubenu-tri-cube", "cubenu-tri-cube.mesh"));
		CubenuEntities.push_back(SEntity("peau-du-loup", "peau-du-loup.mesh"));
		CubenuNodes.push_back(SNode("cubenu-tri-cube", "cubenu-tri-cube"));
		CubenuNodes.push_back(SNode("peau-du-loup", "peau-du-loup"));
		
		CubenuLights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.2f, 0.2f, 0.2f, 1.0f)));

		Cubenu.Create(CubenuEntities, CubenuNodes, CubenuLights, NetConfig);
		SProjectorFrustum pFrustum = Cubenu.CreateProjector("DecalProjectorNode", Vector3(0.0f, 235.911f, -154.772f), Vector3(0.2f, 0.0f, 1.0f));
		Cubenu.ApplyDecalToMaterial("nu_video", "cubenu-tri/lambert7", pFrustum.m_Decal, TextureUnitState::TAM_BORDER);
		Cubenu.ApplyDecalToMaterial("nu_video", "peau-du-loup/peau_nu2ana_test2_ana_peau_damoiselle____Standard__", pFrustum.m_Decal, TextureUnitState::TAM_BORDER);
		Cubenu.ApplyDecalToMaterial("nu_video", "peau-du-loup/peau_nu2lambert3", pFrustum.m_Decal, TextureUnitState::TAM_BORDER);
		Cubenu.ApplyDecalToMaterial("nu_video", "peau-du-loup/peau_nu2lambert4", pFrustum.m_Decal, TextureUnitState::TAM_BORDER);
		Cubenu.ApplyDecalToMaterial("nu_video", "peau-du-loup/peau_nu2NCO_peaucorps_scenomancheveux1", pFrustum.m_Decal, TextureUnitState::TAM_BORDER);
		Cubenu.ApplyDecalToMaterial("nu_video", "peau-du-loup/lambert7", pFrustum.m_Decal, TextureUnitState::TAM_BORDER);
	}
#endif
#if SCENE_SOUFFLE
	//Scene Souffle
	CSceneSouffle Souffle(Engine, "Souffle", 12);
	Scenes.push_back(&Souffle);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("couple-soufle-ana", "couple_soufle_ana.mesh", true));
		Nodes.push_back(SNode("couple-soufle-ana", "couple-soufle-ana"));
		Entities.push_back(SEntity("couple-soufle-nco", "couple_soufle_nco.mesh", true));
		Nodes.push_back(SNode("couple-soufle-nco", "couple-soufle-nco"));
		Entities.push_back(SEntity("soufle-blanche-decors-sol", "soufle-blanche-decors-sol.mesh"));
		Nodes.push_back(SNode("soufle-blanche-decors-sol", "soufle-blanche-decors-sol"));
		Entities.push_back(SEntity("signes", "signes.mesh"));
		Nodes.push_back(SNode("signes", "signes"));
		//Entities.push_back(SEntity("soufle-blanche-decors-planche", "soufle-blanche-decors-planche.mesh"));
		//Nodes.push_back(SNode("soufle-blanche-decors-planche", "soufle-blanche-decors-planche"));
		Entities.push_back(SEntity("ana-blanche", "ana_blanche.mesh", true));
		Nodes.push_back(SNode("ana-blanche", "ana-blanche"));

		Entities.push_back(SEntity("soufle-camera", "soufle-camera.mesh"));
		Nodes.push_back(SNode("soufle-camera", "soufle-camera"));
		

		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.1f, 0.1f, 0.1f, 1.0f)));
		Lights.push_back(SLight("Souffle-spotLight1", Vector3(-289.8428, 39.7118, -23.010), ColourValue(1.0f, 1.0f, 1.0f, 1.0f), ColourValue::Black, Light::LT_SPOTLIGHT, Vector3(289.8428, -39.7118, 23.010)));

		Souffle.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif
#if SCENE_BLANCHE
	//Scene Souffle
	CSceneBlanche Blanche(Engine, "Blanche", 13);
	Scenes.push_back(&Blanche);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("ana-table", "ana-table.mesh", true));
		Nodes.push_back(SNode("ana-table", "ana-table"));

		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.0f, 0.0f, 0.0f, 1.0f)));
		Lights.push_back(SLight("BlancheLight1", Vector3(-128.4, 111.1, -64.7), ColourValue(1.0f, 1.0f, 1.0f, 1.0f)));

		Blanche.Create(Entities, Nodes, Lights, NetConfig);
	}
#endif
	/*
	//Scene Test Particule
	CSceneTestParticule Test(Engine, "TestParticule", 1000);
	Scenes.push_back(&Test);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("TestParticuleglam-petitsloups", "glam-petitsloups.mesh", true));
		Nodes.push_back(SNode("TestParticuleglam-petitsloups", "TestParticuleglam-petitsloups"));

		Entities.push_back(SEntity("TestParticuleglam-petitsloups-sol", "glam-petitsloups-sol.mesh"));
		Nodes.push_back(SNode("TestParticuleglam-petitsloups-sol", "TestParticuleglam-petitsloups-sol"));

		Lights.push_back(SLight("TestParticuleAmbient", Vector3::ZERO, ColourValue(0.1f, 0.1f, 0.1f, 1.0f)));
		Lights.push_back(SLight("TestParticuledirectionalLight1", Vector3::ZERO, ColourValue(0.7f, 0.7f, 0.7f, 1.0f), ColourValue::White, Light::LT_DIRECTIONAL, Vector3(0, -0.5, 1)));

		Test.Create(Entities, Nodes, Lights, NetConfig);
	}
	*/
	/*
	//Scene Test Renaissance
	CSceneTestRenaissance TestRenaissance(Engine, "TestRenaissance", 1001);
	Scenes.push_back(&TestRenaissance);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("TestRenaissanceglam-petitsloups", "glam-petitsloups.mesh", true));
		Nodes.push_back(SNode("TestRenaissanceglam-petitsloups", "TestRenaissanceglam-petitsloups"));

		Lights.push_back(SLight("TestRenaissanceAmbient", Vector3::ZERO, ColourValue(0.1f, 0.1f, 0.1f, 1.0f)));
		Lights.push_back(SLight("TestRenaissancedirectionalLight1", Vector3::ZERO, ColourValue(0.7f, 0.7f, 0.7f, 1.0f), ColourValue::White, Light::LT_DIRECTIONAL, Vector3(0, -0.5, 1)));

		TestRenaissance.Create(Entities, Nodes, Lights, NetConfig);
	}
	*/
	/*
	//Scene Test Fur
	CSceneTestFur Test(Engine, "TestFur", 1002);
	Scenes.push_back(&Test);
	{
		CSceneBase::TCreatorEntities Entities;
		CSceneBase::TCreatorNodes Nodes;
		CSceneBase::TCreatorLights Lights;

		Entities.push_back(SEntity("peau-du-loup", "peau-du-loup.mesh", true));
		Nodes.push_back(SNode("peau-du-loup", "peau-du-loup"));

		Lights.push_back(SLight("Ambient", Vector3::ZERO, ColourValue(0.1f, 0.1f, 0.1f, 1.0f)));
		Lights.push_back(SLight("TestFurdirectionalLight1", Vector3::ZERO, ColourValue(0.7f, 0.7f, 0.7f, 1.0f), ColourValue::White, Light::LT_DIRECTIONAL, Vector3(0, -0.5, 1)));

		Test.Create(Entities, Nodes, Lights, NetConfig);
	}
	*/
	

	CNetBase *pNet = NULL;

	if (NetConfig == e_NCClientR || NetConfig == e_NCClientL)
	{
		pNet = new CNetClient(&Engine, ServerAddress.c_str());
	}
	else
	if (NetConfig == e_NCServer)
	{
		pNet = new CNetServer(&Engine);
	}

	if (NetConfig == e_NCClientR || NetConfig == e_NCClientL || NetConfig == e_NCServer)
	{
		pNet->Create();
	}

	if (NetConfig == e_NCClientR || NetConfig == e_NCClientL || NetConfig == e_NCServer)
	{
		pNet->WaitUntilReady();
		Engine.m_Root.addFrameListener(pNet);
	}


	Engine.startNextScene();
	Engine.m_Root.startRendering(); // will not continue until a frame listener returns false. eg from pressing escape in this example





	if (NetConfig == e_NCClientR || NetConfig == e_NCClientL || NetConfig == e_NCServer)
	{
		pNet->Destroy();
	}

	for (std::vector<CSceneBase *>::iterator It = Scenes.begin(); It != Scenes.end(); ++It)
	{
		(*It)->Destroy();
	}

	XMLPlatformUtils::Terminate();

	return (0);
}

#ifdef __cplusplus
}
#endif